
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>线程池的作用 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>线程池的作用 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">线程池如何通过“线程重用”来提升系统性能？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">线程池中的线程可以被重复使用，避免了频繁创建和销毁线程这一昂贵的操作开销。通过复用线程，线程池减少了性能下降，从而提高了系统的响应速度和吞吐量。</div>
          </div>
          <div class="card-source">来源: 1. 减少线程创建和销毁的开销</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">为什么说控制并发线程数能够提升系统稳定性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过限制线程池中的线程数量，可以防止系统因创建过多并发线程而耗尽CPU或内存等资源。同时，这有助于避免因线程过多导致的过于频繁的上下文切换，从而提高系统整体的稳定性。</div>
          </div>
          <div class="card-source">来源: 2. 控制并发线程数</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">功能</div>
          <div class="card-question">线程池中的“任务队列”机制主要解决了什么问题？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">功能</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">任务队列用于存储尚未执行的任务。它能够平滑地处理任务的提交和执行，主要解决了因任务提交速度快于任务处理速度而可能导致的任务丢失问题。</div>
          </div>
          <div class="card-source">来源: 3. 任务调度和管理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">FixedThreadPool 和 CachedThreadPool 这两种线程池的核心区别是什么？它们分别适用于哪些场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">核心区别在于线程数量是否固定。FixedThreadPool 创建一个固定大小的线程池，适用于负载稳定的任务处理场景。而 CachedThreadPool 会根据任务需求动态调整线程数，适用于任务量不均匀的场景。</div>
          </div>
          <div class="card-source">来源: 6. 线程池的类型和用途</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">当需要确保任务严格按照提交顺序执行时，应选择哪种类型的线程池？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">应该选择单线程池 (SingleThreadExecutor)。因为它只使用一个线程来执行所有任务，从而天然地保证了任务会按照提交的顺序依次执行。</div>
          </div>
          <div class="card-source">来源: 6. 线程池的类型和用途</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在 Java 中，线程池的核心接口是什么？通常使用哪个工厂类来方便地创建不同类型的线程池？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在 Java 中，线程池的核心接口是 ExecutorService。可以通过工厂类 Executors 提供的静态方法（如 Executors.newFixedThreadPool()、Executors.newCachedThreadPool() 等）来方便地创建不同类型的线程池。</div>
          </div>
          <div class="card-source">来源: 7. 线程池的实现</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
